//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <fstream>

#include "ListAncestorMol.h"
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
#define NOFILTER1 1
#define NOFILTER2 1
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
using namespace std;
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
#define TYPE_COINCIDENCE 1
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
namespace SpaceCorelationClusters {

  bool AscendentAncestor(TNode <AncestorMol>* NodeT, void* ref, void* parameters) {
    AncestorMol* ancestorA  = NodeT->Info();
    AncestorMol* ancestorB  = ((TNode <AncestorMol>*)ref)->Info();
    int          level      = (*(int*)parameters) - 1;
    return (*(ancestorA->ListIdAncestor()->Get(level)) < *(ancestorB->ListIdAncestor()->Get(level)))?true:false;
  }

  bool DiffAncestor(TNode <AncestorMol>* NodeT, void* ref, void* parameters) {
    AncestorMol* ancestorA  = NodeT->Info();
    AncestorMol* ancestorB  = ((TNode <AncestorMol>*)ref)->Info();
    int          level      = (*(int*)parameters) - 1;
    if (*(ancestorA->ListIdAncestor()->Get(level)) != *(ancestorB->ListIdAncestor()->Get(level))) return false;
    else {
      if (*(ancestorA->ListIdAncestor()->Get(level)) == *(ancestorA->ListIdAncestor()->Get(0))) {
        NodeT->Info(NULL);
        NodeT->Info(ancestorB);
        ((TNode <AncestorMol>*)ref)->Info(NULL);
        ((TNode <AncestorMol>*)ref)->Info(ancestorA);
      }
      return true;
    }
  }

  bool EqualAncestor(TNode <AncestorMol>* NodeT, void* ref, void* parameters) {
    AncestorMol* ancestorA  = NodeT->Info();
    AncestorMol* ancestorB  = ((TNode <AncestorMol>*)ref)->Info();
    int          level      = (*(int*)parameters) - 1;
    return (*(ancestorA->ListIdAncestor()->Get(level)) == *(ancestorB->ListIdAncestor()->Get(level)))?true:false;
  }

};
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
int main(int argc, char** argv) {

  String* filenameCluster1In;
  String* filenameCluster2In;
  String* filenameOut;
  int     ancestorLevel1, ancestorLevel2;

  if (argc < 5) {
    cout << "Error in the input arguments. The execution must be: " << endl;
    cout << "./ClusterSimilarity <Input Cluster File - 1> <Ancestor Level - 1> <Input Cluster File - 2> <Ancestor Level - 2>" << endl;
    return 0;
  }
  else {
    cout << "---------------------------------------------------------------------------------" << endl;
    cout << " Input Cluster File - 1 : " << argv[1] << endl;
    cout << "     Ancestor Level - 1 : " << argv[2] << endl;
    cout << " Input Cluster File - 2 : " << argv[3] << endl;
    cout << "     Ancestor Level - 2 : " << argv[4] << endl;
    cout << "---------------------------------------------------------------------------------" << endl;
    filenameCluster1In = new String(argv[1]);
    ancestorLevel1     = atoi(argv[2]);
    filenameCluster2In = new String(argv[3]);
    ancestorLevel2     = atoi(argv[4]);
  }

  ListAncestorMol* ancestorCluster1 = new ListAncestorMol();
  ancestorCluster1->FilenameAncestor(filenameCluster1In);
  ancestorCluster1->LoadDataAncestorFiles();

  cout << "Cluster Smilirarity :" << ancestorCluster1->ComputeClusterSimilarity(filenameCluster2In, ancestorLevel1, ancestorLevel2) << endl;

  if (ancestorCluster1) delete ancestorCluster1;

  return 1;

}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//




